import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import * as fs from 'fs';
import { join } from 'path';
import { ConfigEnum } from '../enum/config.enum';

@Injectable()
export class UploadService {
  constructor(private readonly configService: ConfigService) {}
  upload(file) {
    return {
      name: file.originalname,
      url: `/${file.filename}`,
    };
  }

  remove(query: { filePath: string }) {
    fs.unlinkSync(
      join(
        __dirname,
        `../../../${this.configService.get(ConfigEnum.FILE_UPLOADS_DIR || 'uploads')}/${query.filePath}`,
      ),
    );
    return {};
  }
}
